/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopVipUserInfo: {
                shopVipUsers: [],
                total: 0,
                records: 1,
                moreCondition: false,
                vipId: '',
                vipLevels: [{
                    levelName:'全部',
                    vipLevelId:''
                }],
                conditions: {
                    vipName: '',
                    vipTel: '',
                    vipLevel: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listShopVipUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listShopVipLevels();
        },
        _initEvent: function () {
            vc.on('shopVipUser', 'listShopVipUser', function (_param) {
                $that._listShopVipUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShopVipUsers(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopVipUsers: function (_page, _rows) {
                $that.shopVipUserInfo.conditions.page = _page;
                $that.shopVipUserInfo.conditions.row = _rows;
                $that.shopVipUserInfo.conditions.shopId = vc.getCurrentCommunity().shopId;

                let param = {
                    params: $that.shopVipUserInfo.conditions
                };
                //发送get请求
                vc.http.apiGet('/shopVipUser.queryShopVipUser',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.shopVipUserInfo.total = _json.total;
                        $that.shopVipUserInfo.records = _json.records;
                        $that.shopVipUserInfo.shopVipUsers = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopVipUserInfo.records,
                            dataCount: $that.shopVipUserInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopVipUserModal: function () {
                vc.emit('addShopVipUser', 'openAddShopVipUserModal', {});
            },
            _openEditShopVipUserModel: function (_shopVipUser) {
                vc.emit('editShopVipUser', 'openEditShopVipUserModal', _shopVipUser);
            },
            _openDeleteShopVipUserModel: function (_shopVipUser) {
                vc.emit('deleteShopVipUser', 'openDeleteShopVipUserModal', _shopVipUser);
            },
            //查询
            _queryShopVipUserMethod: function () {
                $that._listShopVipUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopVipUserMethod: function () {
                $that.shopVipUserInfo.conditions.vipName = "";
                $that.shopVipUserInfo.conditions.vipTel = "";
                $that.shopVipUserInfo.conditions.vipLevel = "";
                $that._listShopVipUsers(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.shopVipUserInfo.moreCondition) {
                    $that.shopVipUserInfo.moreCondition = false;
                } else {
                    $that.shopVipUserInfo.moreCondition = true;
                }
            },
            _listShopVipLevels: function (_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                let _levels=[{
                    levelName:'全部',
                    vipLevelId:''
                }]
                //发送get请求
                vc.http.apiGet('/shopVipUser.queryShopVipLevel',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        _json.data.forEach(_l=>{
                            _levels.push(_l)
                        })
                        $that.shopVipUserInfo.vipLevels = _levels;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openVipUserAcct: function (_shopVipUser) {
                vc.jumpToPage('/#/pages/goods/shopVipUserAccount?vipId=' + _shopVipUser.vipId);
            },
            _toUserVipDetail:function(_shopVipUser){
                window.open('/#/pages/user/vipDetail?vipId='+_shopVipUser.vipId);
            },
            swatchVipLevel:function(_shopVipUser){
                $that.shopVipUserInfo.conditions.vipLevel = _shopVipUser.vipLevelId;
                $that._listShopVipUsers(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _exportShopVipUser: function () {
                $that.shopVipUserInfo.conditions.pagePath = 'shopVipUser';
                let param = {
                    params: $that.shopVipUserInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/export.exportData', param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        vc.toast(_json.msg);
                        if (_json.code == 0) {
                            vc.jumpToPage('/#/pages/property/downloadTempFile?tab=下载中心&fileType=shopVipUser')
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    });
            },
        }
    });
})(window.vc);
